package com.bltec.emergency.mapper;

import com.bltec.emergency.model.RecordTrain;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RecordTrainMapper {

    //插入一条train记录
    @Insert("insert into record_train (train_name,train_unit,train_department,train_time,train_position,participants_num," +
            "create_by,create_time,enable) " +
            "values(#{trainName},#{trainUnit},#{trainDepartment},#{trainTime},#{trainPosition},#{participantsNum},#{createBy},#{createTime},#{enable})")
    boolean insert(RecordTrain recordTrain);

    //通过trainName字段删除train记录
    @Delete("delete from record_train where train_name=#{trainName}")
    boolean deleteByTrainName(String trainName);

    //通过id设置一条记录为不可用
    @Update("update record_train set enable=0 where id=#{id}")
    boolean setDisableById(Long id);

    //通过id更新一条记录
    @Update("update record_train set train_name=#{trainName},train_unit=#{trainUnit},train_department=#{trainDepartment}," +
            "train_time=#{trainTime},train_position=#{trainPosition},participants_num=#{participantsNum},update_by=#{updateBy},update_time=#{updateTime} where id=#{id}")
    boolean updateTrainById(RecordTrain recordTrain);

    //查找符合trainName字段的记录
    @Select("select * from record_train where train_name =#{trainName} and enable=1")
    RecordTrain getTrainByTrainName(String trainName);

    //查找符合TrainName字段的记录的id
    @Select("select id from record_train where train_name =#{trainName} and enable=1")
    Long getIdByTrainName(String trainName);

    //查找符合id字段的记录
    @Select("select * from record_train where id =#{id} and enable=1")
    RecordTrain getTrainById(Long id);

    //查找所有记录
    @Select("select * from record_train where enable=1")
    List<RecordTrain> selectAll();
}